package com.niiwoo.civet.trade.service.dubbo.configure;

import com.alibaba.dubbo.config.annotation.Service;
import com.niiwoo.civet.trade.dao.entity.BorrowFlowConfig;
import com.niiwoo.civet.trade.dto.response.BorrowFlowConfigResponseDTO;
import com.niiwoo.civet.trade.enums.BorrowFlowConfigTypeEnum;
import com.niiwoo.civet.trade.service.configure.BorrowFlowConfigDubboService;
import com.niiwoo.civet.trade.service.local.configure.BorrowFlowConfigLocalService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author DELL  2018/4/3
 * @description
 */

@Service(version = "1.0.0")
public class BorrowFlowConfigDubboServiceImpl implements BorrowFlowConfigDubboService {

    @Autowired
    private BorrowFlowConfigLocalService borrowFlowConfigLocalService;

    @Override
    public BorrowFlowConfigResponseDTO queryBorrowFlowConfig(BorrowFlowConfigTypeEnum type) {
        BorrowFlowConfigResponseDTO dto =new BorrowFlowConfigResponseDTO();
        BorrowFlowConfig config =borrowFlowConfigLocalService.queryByType(type);
        return dto;
    }

    @Override
    public List<BorrowFlowConfigResponseDTO> queryBorrowFlowConfigList() {
        List<BorrowFlowConfigResponseDTO> dtoList =new ArrayList<>();
        List<BorrowFlowConfig> configList = borrowFlowConfigLocalService.queryList();
        if (configList != null && !configList.isEmpty()){
            for (BorrowFlowConfig entity : configList){
                BorrowFlowConfigResponseDTO dto =new BorrowFlowConfigResponseDTO();
                dto.setContent(entity.getTitle());
                dto.setImageLink(entity.getImageLink());
                dto.setIsShow(entity.getIsShow());
                dto.setLink(entity.getLink());
                dto.setType(entity.getType());
                dtoList.add(dto);
            }
        }
        return dtoList;
    }
}
